package com.xunan.demo.controller;

import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.xunan.demo.pojo.CommonResult;
import com.xunan.demo.service.AlipayUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class AlipayUserController {

    @Resource
    AlipayUserService alipayUserService;

    /**
     * 获取支付宝用户信息
     * 参考文档：https://opendocs.alipay.com/mini/introduce/authcode
     *
     * @param userCode    用户授权码
     * @param refreshCode 刷新令牌。通过该令牌可以刷新access_token
     * @return 支付宝用户信息
     */
    @GetMapping("/alipay-user/getMiniAppUserInfo")
    public CommonResult<AlipaySystemOauthTokenResponse> getMiniAppUserInfo(String userCode, String refreshCode) {
        return alipayUserService.getMiniAppUserInfo(userCode, refreshCode);
    }

}
